home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / devs / console.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  5KB  |  204 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: console.c,v 1.3 1996/10/24 15:50:21 aros Exp $
  4.     $Log: console.c,v $
  5.     Revision 1.3  1996/10/24 15:50:21  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.2  1996/09/11 16:54:19  digulla
  9.     Always use AROS_SLIB_ENTRY() to access shared external symbols, because
  10.         some systems name an external symbol "x" as "_x" and others as "x".
  11.         (The problem arises with assembler symbols which might differ)
  12.  
  13.     Revision 1.1  1996/08/23 17:32:23  digulla
  14.     Implementation of the console.device
  15.  
  16.  
  17.     Desc:
  18.     Lang:
  19. */
  20. #include <exec/resident.h>
  21. #include <devices/inputevent.h>
  22. #include <clib/exec_protos.h>
  23. #include <clib/console_protos.h>
  24. #include <aros/libcall.h>
  25. #ifdef __GNUC__
  26. #    include "console_gcc.h"
  27. #endif
  28.  
  29. static const char name[];
  30. static const char version[];
  31. static const APTR inittabl[4];
  32. static void *const functable[];
  33. static const UBYTE datatable;
  34.  
  35. struct consolebase *AROS_SLIB_ENTRY(init,Console)();
  36. void AROS_SLIB_ENTRY(open,Console)();
  37. BPTR AROS_SLIB_ENTRY(close,Console)();
  38. BPTR AROS_SLIB_ENTRY(expunge,Console)();
  39. int AROS_SLIB_ENTRY(null,Console)();
  40. void AROS_SLIB_ENTRY(beginio,Console)();
  41. LONG AROS_SLIB_ENTRY(abortio,Console)();
  42.  
  43. extern struct InputEvent * AROS_SLIB_ENTRY(CDInputHandler,Console) ();
  44. extern LONG AROS_SLIB_ENTRY(RawKeyConvert,Console) ();
  45. static const char end;
  46.  
  47. int AROS_SLIB_ENTRY(entry,Console)(void)
  48. {
  49.     /* If the device was executed by accident return error code. */
  50.     return -1;
  51. }
  52.  
  53. const struct Resident Console_resident=
  54. {
  55.     RTC_MATCHWORD,
  56.     (struct Resident *)&Console_resident,
  57.     (APTR)&end,
  58.     RTF_AUTOINIT,
  59.     1,
  60.     NT_LIBRARY,
  61.     0,
  62.     (char *)name,
  63.     (char *)&version[6],
  64.     (ULONG *)inittabl
  65. };
  66.  
  67. static const char name[]="console.device";
  68.  
  69. static const char version[]="$VER: console 1.0 (23.8.96)\n\015";
  70.  
  71. static const APTR inittabl[4]=
  72. {
  73.     (APTR)sizeof(struct consolebase),
  74.     (APTR)functable,
  75.     (APTR)&datatable,
  76.     &AROS_SLIB_ENTRY(init,Console)
  77. };
  78.  
  79. static void *const functable[]=
  80. {
  81.     &AROS_SLIB_ENTRY(open,Console),
  82.     &AROS_SLIB_ENTRY(close,Console),
  83.     &AROS_SLIB_ENTRY(expunge,Console),
  84.     &AROS_SLIB_ENTRY(null,Console),
  85.     &AROS_SLIB_ENTRY(beginio,Console),
  86.     &AROS_SLIB_ENTRY(abortio,Console),
  87.     &AROS_SLIB_ENTRY(CDInputHandler,Console),
  88.     &AROS_SLIB_ENTRY(RawKeyConvert,Console),
  89.     (void *)-1
  90. };
  91.  
  92. AROS_LH2(struct consolebase *, init,
  93.  AROS_LHA(struct consolebase *, consoleDevice, D0),
  94.  AROS_LHA(BPTR,              segList,   A0),
  95.        struct ExecBase *, sysBase, 0, Console)
  96. {
  97.     AROS_LIBFUNC_INIT
  98.  
  99.     /* Store arguments */
  100.     consoleDevice->sysBase = sysBase;
  101.     consoleDevice->seglist = segList;
  102.  
  103.     consoleDevice->device.dd_Library.lib_OpenCnt=1;
  104.  
  105.     return consoleDevice;
  106.     AROS_LIBFUNC_EXIT
  107. }
  108.  
  109. AROS_LH3(void, open,
  110.  AROS_LHA(struct IORequest *, ioreq, A1),
  111.  AROS_LHA(ULONG,              unitnum, D0),
  112.  AROS_LHA(ULONG,              flags, D0),
  113.        struct consolebase *, ConsoleDevice, 1, Console)
  114. {
  115.     AROS_LIBFUNC_INIT
  116.  
  117.     /* Keep compiler happy */
  118.     unitnum=0;
  119.     flags=0;
  120.  
  121.     /* I have one more opener. */
  122.     ConsoleDevice->device.dd_Library.lib_Flags&=~LIBF_DELEXP;
  123.  
  124.     AROS_LIBFUNC_EXIT
  125. }
  126.  
  127. AROS_LH1(BPTR, close,
  128.  AROS_LHA(struct IORequest *, ioreq, A1),
  129.        struct consolebase *, ConsoleDevice, 2, Console)
  130. {
  131.     AROS_LIBFUNC_INIT
  132.  
  133.     /* Let any following attemps to use the device crash hard. */
  134.     ioreq->io_Device=(struct Device *)-1;
  135.     return 0;
  136.     AROS_LIBFUNC_EXIT
  137. }
  138.  
  139. AROS_LH0(BPTR, expunge, struct consolebase *, ConsoleDevice, 3, Console)
  140. {
  141.     AROS_LIBFUNC_INIT
  142.  
  143.     /* Do not expunge the device. Set the delayed expunge flag and return. */
  144.     ConsoleDevice->device.dd_Library.lib_Flags|=LIBF_DELEXP;
  145.     return 0;
  146.     AROS_LIBFUNC_EXIT
  147. }
  148.  
  149. AROS_LH0I(int, null, struct consolebase *, ConsoleDevice, 4, Console)
  150. {
  151.     AROS_LIBFUNC_INIT
  152.     return 0;
  153.     AROS_LIBFUNC_EXIT
  154. }
  155.  
  156. AROS_LH1(void, beginio,
  157.  AROS_LHA(struct IORequest *, ioreq, A1),
  158.        struct consolebase *, ConsoleDevice, 5, Console)
  159. {
  160.     AROS_LIBFUNC_INIT
  161.     LONG error=0;
  162.  
  163.     /* WaitIO will look into this */
  164.     ioreq->io_Message.mn_Node.ln_Type=NT_MESSAGE;
  165.  
  166.     /*
  167.     Do everything quick no matter what. This is possible
  168.     because I never need to Wait().
  169.     */
  170.     switch (ioreq->io_Command)
  171.     {
  172.     default:
  173.     error=ERROR_NOT_IMPLEMENTED;
  174.     break;
  175.     }
  176.  
  177.     /* If the quick bit is not set send the message to the port */
  178.     if(!(ioreq->io_Flags&IOF_QUICK))
  179.     ReplyMsg (&ioreq->io_Message);
  180.  
  181.     /* Trigger a rescedule every now and then */
  182.     if(SysBase->TaskReady.lh_Head->ln_Pri==SysBase->ThisTask->tc_Node.ln_Pri&&
  183.        SysBase->TDNestCnt<0&&SysBase->IDNestCnt<0)
  184.     {
  185.     SysBase->ThisTask->tc_State=TS_READY;
  186.     Enqueue(&SysBase->TaskReady,&SysBase->ThisTask->tc_Node);
  187.     Switch();
  188.     }
  189.  
  190.     AROS_LIBFUNC_EXIT
  191. }
  192.  
  193. AROS_LH1(LONG, abortio,
  194.  AROS_LHA(struct IORequest *, ioreq, A1),
  195.        struct consolebase *, ConsoleDevice, 6, Console)
  196. {
  197.     AROS_LIBFUNC_INIT
  198.     /* Everything already done. */
  199.     return 0;
  200.     AROS_LIBFUNC_EXIT
  201. }
  202.  
  203. static const char end=0;
  204.